<template>
  <div class="c-bg-sgray">
    <!-- 有商品 -->
    <div class="c-flex-row c-aligni-center c-justify-sb c-ph24 c-pv28" v-if="shopCartList.length > 0">
      <span class="c-fs32 c-fc-xblack c-lh44 c-fw-b">购物车</span>
      <div class="c-fs24 c-fc-xblack" @click="clickEdit()">{{isEdit ? "完成" : "编辑"}}</div>
    </div>
    <div class="c-bg-sgray c-ph24">
      <div v-if="shopCartList.length > 0" class="c-pt12">
        <div v-for="(item,index) in shopCartList" :key="item.no" class="c-bg-white c-mb16 c-br8" :class="[!item.mcbId ? 'c-flex-row c-pv20' : '']">
          <!-- 普通商品 -->
          <template v-if="!item.mcbId">
            <div class="c-flex-row c-flex-center c-ww76 c-hh140">
              <span class="iconfont c-fs34 c-fc-sgray" v-show="item.isChecked != 1" @click="clickItemSelect(index,true)">&#xe797;</span>
              <span class="iconfont c-fs34 theme-fc" v-show="item.isChecked == 1" @click="clickItemSelect(index,false)">&#xe6b1;</span>
            </div>
            <div class="c-flex-row c-w0 c-flex-grow1">
              <div class="c-text-hidden c-br16 c-p c-ww140 c-hh140" @click="clickShop(item.mgId)">
                <CoverImg :coverSizeClass="'c-w100 c-h c-br16 c-text-hidden'" imgClass="c-br16" :coverUrl="item.avatar" :prodType="ckFrom.shopping"/>
              </div>
              <div class="c-ml20 c-flex-column cart-name-box c-flex-grow1 c-w0 c-minh140 c-justify-sb">
                <div>
                  <div class="c-fs24 c-fc-xblack c-flex-row" @click="clickShop(item.mgId)">
                    <span class="c-fs24 c-flex-grow1 c-w0 c-text-ellipsis2 c-pr24">
                      <span v-if="item.isMarketing == 1 && item.optimal && item.optimal.optimalPriceType == 101" class="c-fs16 theme-bg c-fc-white c-mr4 c-textAlign-c c-br4 c-pv4 c-ph4">限时{{Number(item.flashSales.price) == 0 ? '免费' : '折扣'}}</span>
                      {{item.name}}
                    </span>
                  </div>
                  <div class="c-fs20 c-fc-gray c-mt16 c-bg-f4f5f7 c-pv6 c-ph8 c-inlineblack c-vcAlign-middle c-br8" v-if="item.subSpec" @click="onShowSpecifications(item.mgId, item.mcId, index, true)">
                    规格：{{item.subSpec}}
                    <i class="iconfont c-fs16 c-ml4 c-fw-b scale8">&#xe6a9;</i>
                  </div>
                  <div class="c-fs20 c-fc-gray c-mt12" v-if="(item.minOrderQuantity && item.minOrderQuantity>1) || (isInFlashSales(item) && item.flashSales.limit != 0)">
                    <span v-if="item.minOrderQuantity && item.minOrderQuantity>1">起售：{{item.minOrderQuantity}}</span>
                    <span v-if="isInFlashSales(item) && item.flashSales.limit != 0">(限购{{item.flashSales.limit}}件)</span>
                  </div>
                </div>
                <div>
                  <div class="c-flex-row c-aligni-center c-justify-sb c-w100 c-mt12">
                    <div class="c-fs26 theme-fc c-mr4 c-fw-b"><span class="c-fs20 c-fw-n">{{'￥' | iosPriceFilter}}</span>{{item.optimal ? item.optimal.optimalPrice : Number(item.price).toFixed(2)}}</div>
                    <div class="c-flex-row c-justify-center" @click.stop="isChangeNum=true">
                      <div class="c-flex-row c-flex-center">
                        <div class="operation-button sub-button" @click="subNum(index)" :class="(item.minOrderQuantity * 1 > 1) && (quantityList[index] <= (item.minOrderQuantity * 1)) || ((item.minOrderQuantity * 1 <= 1) && quantityList[index] == 1) ? 'disabled-click c-fc-xblack':''"><span class="iconfont icon-subtract"></span></div>
                        <input type="text" class="bgF4F5F7 c-fc-xblack" @input="changeInputNum(index)" @focus="inputFocus(index)" v-model="quantityList[index]" v-on:blur="finishInput(index)" />
                        <div class="operation-button add-button" @click="addNum(index)" :class="quantityList[index] >= shopNumberMax(item) ? 'disabled-click c-fc-xblack':''"><span class="iconfont icon-add"></span></div>
                      </div>
                    </div>
                  </div>
                  <div class="c-fs20 theme-fc c-mt12" v-if="item.priceTracking > 0">比加入时降￥{{item.priceTracking}}</div>
                  <div class="c-fs22 c-fc-gray c-text-decoration-through c-mt12" v-if="item.originalPrice * 1 > 0"><span v-if="item.originalPrice * 1 > 0">{{'￥' | iosPriceFilter}}</span>{{item.originalPrice * 1 > 0 ? item.originalPrice :''}}</div>
                </div>
              </div>
            </div>
          </template>
          <!-- 满减活动商品 -->
          <template v-else-if="item.mcbId">
            <div class="c-ph20">
              <div class="c-bd-b1-f5 c-flex-row c-aligni-center c-pv24">
                <div class="c-flex-row c-aligni-center c-justify-sb c-flex-grow1 c-w0" @click="changeCurrentMcbId(item.mcbId)">
                  <div class="c-flex-row c-aligni-center c-w0 c-flex-grow1">
                    <div class="c-text-ellipsis1 c-fs20 c-fc-xblack c-hh36 c-lh36">
                      <span class="c-fc-lorange c-br8 tagBg1 c-ph8 c-lh28 c-pv2 c-fs20 c-mr8" v-if="(item.contents.some(it => {return it.isDiscount == 1})) || (item.contents.some(it => {return (it.isSendDiscount == 1 || it.isSendPoints == 1 || it.isSendProd == 1)})) || (item.contents.some(it => {return it.isFreeShipping == 1}))">
                        <!-- 满折/满赠/包邮 -->
                        {{item.contents.some(it => {return it.isDiscount == 1}) ? '满减' : ''}}
                        {{item.contents.some(it => {return (it.isSendDiscount == 1 || it.isSendPoints == 1 || it.isSendProd == 1)}) ? ((item.contents.some(it => {return it.isDiscount == 1}) ? '/' : '') + '满赠') : ''}}
                        {{item.contents.some(it => {return it.isFreeShipping == 1}) ? (item.contents.some(it => {return (it.isDiscount == 1)}) || item.contents.some(it => {return (it.isSendDiscount == 1 || it.isSendPoints == 1 || it.isSendProd == 1)}) ? '/' : '') + '包邮' : ''}}
                      </span>
                      <span>{{getActivityTxt(item.mcbId, item.ruleType)}}</span>
                    </div>
                  </div>
                  <div class="c-flex-row c-aligni-center">
                    <div class="c-flex-row c-aligni-center c-fs20 c-fc-xblack">
                      <span class="c-lh24">查看</span>
                      <span class="iconfont c-ml4 c-fs16">&#xe635;</span>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div v-for="(mItem, mIndex) in item.products" :key="mItem.mcbId">
              <div class="c-w100 c-flex-row c-aligni-start c-pv20" :class="mIndex == item.products.length - 1 ? '' :'c-bd-b1-f5'">
                <div class="c-flex-row c-flex-center c-ww76 c-hh140">
                  <span class="iconfont c-fs34 c-fc-sgray" v-show="mItem.isChecked != 1" @click="clickItemSelect(index,true, mIndex)">&#xe797;</span>
                  <span class="iconfont c-fs34 theme-fc" v-show="mItem.isChecked == 1" @click="clickItemSelect(index,false, mIndex)">&#xe6b1;</span>
                </div>
                <div class="c-ww140 c-hh140 c-text-hidden c-br16 c-p" @click="clickShop(mItem.mgId)">
                  <CoverImg :coverSizeClass="'c-w100 c-h c-br16 c-text-hidden'" imgClass="c-br16" :coverUrl="mItem.avatar" :prodType="ckFrom.shopping"/>
                </div>
                <div class="c-pl20 c-flex-column cart-name-box c-justify-sb c-flex-grow1 c-w0">
                  <div>
                    <div class="c-fs24 c-fc-xblack c-flex-row" @click="clickShop(mItem.mgId)">
                      <span class="c-fs24 c-flex-grow1 c-w0 c-text-ellipsis2 c-pr24">{{mItem.name}}</span>
                    </div>
                    <div class="c-flex-row c-aligni-center">
                      <span class="c-fs20 c-fc-gray c-mt15 c-bg-f6 c-pv6 c-ph8 c-inlineblack c-vcAlign-middle c-br4" v-if="mItem.subSpec" @click="onShowSpecifications(mItem.mgId, mItem.mcId, index, true, mIndex)">
                        规格：{{mItem.subSpec}}
                        <i class="iconfont c-fs16 c-fc-sgray c-ml12 c-fw-b scale8">&#xe6a9;</i>
                      </span>
                      <span class="c-fs20 c-fc-gray c-mt16 c-bg-f4f5f7 c-pv6 c-ph8 c-inlineblack c-vcAlign-middle c-br8" v-if="getCashBackUse(item) && getCashBackUse(item).isSendProd == 1" @click="clickShowPresent(item)">
                        赠品×{{getCashBackUse(item).sendProdList.length}}
                        <i class="iconfont c-fs16 c-ml4 c-fw-b scale8">&#xe6a9;</i>
                      </span>
                    </div>
                    <div class="c-fs20 c-fc-gray c-mt15" v-if="(mItem.minOrderQuantity && mItem.minOrderQuantity>1)">
                      <span v-if="mItem.minOrderQuantity && mItem.minOrderQuantity>1">起售：{{mItem.minOrderQuantity}}</span>
                    </div>
                  </div>
                  <div>
                    <div class="c-flex-row c-aligni-center c-justify-sb c-w100 c-mt15">
                      <div class="c-fs26 theme-fc c-mr4 c-fw-b"><span class="c-fs20 c-fw-n">{{'￥' | iosPriceFilter}}</span>{{Number(mItem.flashSales && mItem.flashSales.sales.status ==2 ? mItem.flashSales.price : mItem.price).toFixed(2)}}</div>
                      <div class="c-flex-row c-justify-center" @click.stop="isChangeNum=true">
                        <div class="c-flex-row c-flex-center" v-if="quantityList && quantityList[index] && mItem">
                          <div class="operation-button sub-button" @click="subNum(index, mIndex)" :class="(mItem.minOrderQuantity * 1 > 1) && (quantityList[index].itemQua[mIndex] <= (mItem.minOrderQuantity * 1)) || ((mItem.minOrderQuantity * 1 <= 1) && quantityList[index].itemQua[mIndex] == 1) ? 'disabled-click c-fc-xblack':''"><span class="iconfont icon-subtract"></span></div>
                          <input type="text" class="bgF4F5F7 c-fc-xblack" @input="changeInputNum(index, mIndex)" @focus="inputFocus(index, mIndex)" v-model="quantityList[index].itemQua[mIndex]" v-on:blur="finishInput(index, mIndex)" />
                          <div class="operation-button add-button" @click="addNum(index, mIndex)" :class="quantityList[index].itemQua[mIndex] >= shopNumberMax(mItem) ? 'disabled-click c-fc-xblack':''"><span class="iconfont icon-add"></span></div>
                        </div>
                      </div>
                    </div>
                    <div class="c-fs20 theme-fc c-mt12" v-if="mItem.priceTracking > 0">比加入时降￥{{mItem.priceTracking}}</div>
                    <div class="c-fs22 c-fc-gray c-text-decoration-through c-mt12" v-if="mItem.originalPrice * 1 > 0"><span v-if="mItem.originalPrice * 1 > 0">{{'￥' | iosPriceFilter}}</span>{{mItem.originalPrice * 1 > 0 ? mItem.originalPrice :''}}</div>
                  </div>
                  <div class="c-flex-row c-aligni-center c-justify-sb c-mt12 c-pr16">
                    <span class="c-fs20 c-fc-xblack">满减赠 {{getEndTime(item.endTime)}}</span>
                    <div class="c-flex-row c-aligni-center c-fs20 theme-fc" @click="gocashBackAct(item.mcbId)">
                      <span class="c-lh24">去逛逛</span>
                      <span class="iconfont c-ml4 c-fs16">&#xe635;</span>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </template>
        </div>
        <div class="c-fc-sgray c-fs20 c-textAlign-c c-pv20" v-show="dataStatus == 'LOADING'">{{'加载中...'}}</div>

      </div>
      <!-- 购物车为空 -->
      <div v-if="shopCartList.length == 0 && cartInvalidGoods.length == 0" class="c-bg-f3">
        <div class="c-flex-column c-justify-center c-aligni-center">
          <img class="shop-cart-empty-img" src="https://kposshzcdn.ckjr001.com/admin/material/9_material_admin/image/assets/img_cart_empty.png" alt="暂无图片" />
          <div class="c-fc-sblack c-fs24 c-pt60 c-pb24">你还没有购买任何商品</div>
          <div class="btn-cart-visit c-fs28 c-mb30" @click="clickVisit">逛一逛</div>
        </div>
        <shop-recommend v-if="recommendList.length > 0" :recommendList="recommendList"></shop-recommend>
      </div>
      <!-- 失效列表 -->
      <div class="c-mt12 c-bg-white c-br8 c-ph24" :class="shopCartList.length == 0?'':''" v-if="cartInvalidGoods.length > 0">
        <div class="c-flex-row c-justify-sb c-alignc-center c-pv20">
          <div class="c-fs24 c-fc-xblack">失效商品{{cartInvalidGoods.length}}件</div>
          <div class="c-fs22 theme-fc" @click="checklearInvalidGoods">清空失效商品</div>
        </div>
        <div class="c-pv24 c-flex-row c-aligni-center c-bd-t1-f6" v-for="(item, index) in cartInvalidGoods" :key="index">
          <div class="c-flex-row c-aligni-center c-ww52 c-hh140">
            <i class="sxIcon"></i>
          </div>
          <div class="c-ww140 c-hh140 c-br12 c-text-hidden c-mr20 c-p">
            <CoverImg :coverSizeClass="'c-w100 c-h c-br16 c-text-hidden'" imgClass="c-br16" :coverUrl="item.avatar" :prodType="ckFrom.shopping"/>
          </div>
          <div class="c-flex-grow1 c-w0 c-flex-column c-justify-sb c-hh140">
            <div class="">
              <div class="c-fs24 c-text-ellipsis2" :class="item.status == -2 || item.status == -1 ? 'c-fc-gray' : 'c-fc-xblack'">{{item.name}}</div>
              <div class="c-fs20 c-fc-gray c-mt10" v-if="item.subSpec && item.subSpec != '' && item.subSpec != null">规格：{{item.subSpec}}</div>
            </div>
            <!-- 状态：1-库存不足 0-下架 -1删除 -->
            <div class="c-flex-row c-justify-sb c-aligni-center c-fs22 c-fc-gray">
              <div v-if="item.status == 1">请重新选择商品规格</div>
              <div v-if="item.status == -2 || item.status == -1">该商品已不能购买</div>
              <div v-if="item.status == 1" class="c-flex-row c-aligni-center c-justify-center c-ww88 c-hh44 c-br22 theme-fc theme-bd1" @click="onShowSpecifications(item.mgId,item.mcId)">
                <div>重选</div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div v-if="dataStatus == 'NO_MORE_DATA'" class="c-fc-sgray c-fs20 c-textAlign-c c-pv20">
        我也是有底线的
      </div>
      <!-- 规格弹窗 -->
      <shop-spec ref="shopSpec" v-if="showSpecifications" @confirmSpec="joinCart" @goShopDetail="clickShop" @closeSpec="closeSpecModal"></shop-spec>

      <!-- 满减赠赠品半弹窗 -->
      <cj-popup v-model="showPresent" position="bottom" round :closeable="true" :closeIcon="'c-fs20 c-fc-gray'" class="changeline-popup" @closed="showPresent = false">
        <div class="c-p c-ph24 c-bg-sgray" v-if="currentActivity">
          <div class="c-flex-row c-aligni-center c-pv20">
            <span class="c-fs28 c-flex-grow1 c-w0 c-textAlign-c c-fw-b">赠品</span>
            <span class="c-fs20 iconfont c-fc-gray" @click="showPresent = false">&#xe61b;</span>
          </div>
          <div class="c-fs22 c-mt24 c-fw-b">赠品×{{currentActivity.sendProdList.length}}</div>
          <div class="c-bg-white c-ph24 c-br14 c-mt16 c-pv28">
            <div class="c-contexty-scroll c-maxh70vh">
              <div
                v-for="(it, i) in currentActivity.sendProdList"
                :class="[
                  i == 0 && currentActivity.sendProdList.length != 1 ? 'c-pb28' :
                  i == currentActivity.sendProdList.length - 1 && currentActivity.sendProdList.length != 1 ? 'c-pt28' :
                  (currentActivity.sendProdList.length - 1 != 0 || i != currentActivity.sendProdList.length - 1 ? 'c-pv28' : ''),
                  i == currentActivity.sendProdList.length - 1 ? '' : 'c-bd-b1-f6']" :key="i">
                <div class="c-w100 c-flex-row c-aligni-start">
                  <div class="c-ww140 c-hh140" @click="clickShop(it.prodId)">
                    <CoverImg :coverUrl="it.cover" :coverSizeClass="'c-w100 c-h c-br16 c-text-hidden'" imgClass="c-br16" :prodType="ckFrom.shopping"/>
                  </div>
                  <div class="c-pl20 c-flex-column c-hh140 c-justify-sb c-flex-grow1 c-w0">
                    <div class="c-fs24 c-lh34 c-text-ellipsis2 c-fc-xblack">{{it.prodName}}</div>
                    <div class="c-flex-row c-aligni-center c-justify-sb">
                      <div class="c-fs26">
                        <span class="c-fc-xmlred c-fw-b"><span class="c-fs20">{{'￥' | iosPriceFilter}}</span>0.00</span>
                        <span class="c-fc-gray c-text-decoration-through c-ml12 c-fs22" v-if="it.price * 1 > 0">
                          {{'￥' | iosPriceFilter}}{{it.price}}
                        </span>
                      </div>
                      <div class="c-fs22 c-fc-xblack">x{{it.number}}</div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </cj-popup>

      <!-- 活动规则 -->
      <cj-popup v-model="showRule" position="bottom" round :closeable="true" :closeIcon="'c-fs20 c-fc-gray'" class="changeline-popup" @closed="showRule = false">
        <div class="c-p">
          <div class="c-flex-row c-aligni-center c-pv20 c-ph24">
            <span class="c-fs28 c-flex-grow1 c-w0 c-textAlign-c c-fw-b">活动详情</span>
            <span class="c-fs20 iconfont c-fc-gray" @click="showRule = false">&#xe61b;</span>
          </div>
          <div class="c-pb24 c-ph24 c-pb80" v-if="currentMcb">
            <div class="c-fs22 c-fw-b c-fc-xblack">活动时间</div>
            <div class="c-fs24 c-fc-xblack c-mt12">{{(currentMcb.startTime).replace(/-/g, '.')}} 至 {{(currentMcb.endTime).replace(/-/g, '.')}}</div>
            <div class="c-fs22 c-fw-b c-fc-xblack c-mt36">活动内容</div>
            <div class="c-fs22 c-fc-xblack c-mt24">
              <div class="c-pv16 c-flex-row c-aligni-start" v-if="!(currentMcb.contents.every(item => {return item.isDiscount == -1}))">
                <div class="c-fc-lorange c-br8 tagBg1 c-ph8 c-lh28 c-pv2 c-fs20" :class="theme == 'mb7_black' ? 'c-bg-g c-fc-g' : 'theme-bg-10 theme-fc'">满减</div>
                <div class="c-w0 c-flex-grow1 c-flex-row c-aligni-center c-justify-sb c-ml30">
                  <div class="c-lh34 c-fc-xblack c-fs24">{{getCashBackTxt}}</div>
                </div>
              </div>
              <div class="c-flex-row c-aligni-start c-pv16" v-if="currentMcb.contents.filter(item => {return item.isSendPoints == 1 || item.isSendDiscount == 1 || item.isSendProd == 1}).length > 0">
                <div class="c-fc-lorange c-br8 tagBg1 c-ph8 c-lh28 c-pv2 c-fs20" :class="theme == 'mb7_black' ? 'c-bg-g c-fc-g' : 'theme-bg-10 theme-fc'">满赠</div>
                <div class="c-h c-w0 c-flex-grow1 c-ml30 c-fs24 c-lh34">
                  <span v-for="(item, index) in currentMcb.contents.filter(item => {return item.isSendPoints == 1 || item.isSendDiscount == 1 || item.isSendProd == 1})" :key="index" class="c-lh24 c-fc-xblack">
                    {{item.detail ? item.detail.title : ''}},
                    <span v-for="(it, i) in item.sendProdList" :key="i">
                      送{{it.number}}件<span @click.stop="goShopDetail(it.prodId)">{{it.prodName}}</span>{{i == (item.sendProdList.length - 1) ? '' : '、'}}
                    </span>{{getCashBackPresent(item)}}；
                  </span>
                </div>
              </div>
              <div class="c-pv12 c-flex-row c-aligni-center" v-if="currentMcb.contents.filter(item => {return item.isFreeShipping == 1}).length > 0">
                <span class="c-fc-lorange c-br8 tagBg1 c-ph8 c-lh28 c-pv2 c-fs20" :class="theme == 'mb7_black' ? 'c-bg-g c-fc-g' : 'theme-bg-10 theme-fc'">包邮</span>
                <div class="c-w0 c-flex-grow1 c-flex-row c-aligni-center c-justify-sb c-ml30">
                  <div class="c-lh34 c-fc-xblack c-fs24">{{getFreeShipping}}</div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </cj-popup>
      <div v-if="shopCartList.length > 0" class="shop-cart-bottom c-bd-t1 c-flex-row c-aligni-center c-justify-sb c-w100 c-p-l0">
        <div class="c-flex-row c-hh42 c-aligni-center c-pl24">
          <span class="iconfont c-fs34 c-fc-sgray" v-show="!selectAll" @click="clickSelectAll">&#xe797;</span>
          <span class="iconfont c-fs34 theme-fc" v-show="selectAll" @click="clickSelectAll">&#xe6b1;</span>
          <span class="c-fs24 c-pl10" @click="clickSelectAll">全选</span>
        </div>
        <div class="c-flex-row c-aligni-center c-pr16 c-flex-1 c-justify-sb">
          <div v-if="!isEdit" class=" c-flex-column c-flexw-wrap">
            <span class="c-fs24 c-fc-xblack c-pl24 c-flex-row c-aligni-center">
              已选{{checkedNum}}件，合计：
              <span class="c-fs28 theme-fc">
                <span class="c-fs22">{{'￥' | iosPriceFilter}}</span><span v-html="getTotalPrice"></span>
              </span>
            </span>
            <span class="c-fs22 c-fc-gray c-pl24">优惠减：{{'￥' | iosPriceFilter}}{{cashBackReduce}}</span>
          </div>
          <div v-if="!isEdit" class="c-fs24 c-fc-white c-br36 c-lh34 c-pv16 theme-bg-gradient c-textAlign-c c-ww140 c-ml16" @click="clickSettlement">去结算</div>
          <div v-if="isEdit" class="c-fs24 c-fc-white c-br36 c-lh34 c-pv16 theme-bg-gradient c-textAlign-c c-ww176 c-ml20" @click="delShopCart()">删除</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import ShopRecommend from "@/components/templates/shopRecommend.vue";
import shopSpec from "@/components/templates/shop/shopSpec.vue";
import CoverImg from '@/components/templates/common/coverImg.vue';
import { utilJs } from "@/utils/common.js";
import { getBindPhoneSetting } from "@/utils/checkUnBindPhone.js";
let pageIndex = 1;
let sourceCartList = [];
let selectArr = []; // 选择的商品
export default {
  name: "ShopCart",
  components: {
    ShopRecommend,
    shopSpec,
    CoverImg
  },
  props: [],
  data() {
    return {
      theme: localStorage.getItem("colorName") ? localStorage.getItem("colorName") : "mb5_default",
      dataStatus: 'HAS_MORE_DATA',
      isEdit: false, //是否编辑状态
      totalPrice: 0.0,
      selectAll: false, //是否全选
      shopCartList: [], //购物车列表
      cartInvalidGoods: [], // 失效列表
      recommendList: [], //推荐商品列表
      delShopIds: [], //要删除的商品ID
      freeShipping: null,
      showSpecifications: false, // 重选规格弹窗
      shopInfo: null, // 商品信息
      specItems: [], // 选中商品小类列表
      specItemInfos: [], // 每个规格商品的信息
      currentSpecItemInfos: null, // 当前选中的规格
      flashSales: null, // 限购（重选规格）
      currentMcId: -1, // 当前选中的购物车id
      currentMgId: -1, // 当前选中的商品id
      currentGsiiId: -1, //当前选中的商品gsiiId
      currentPrice: 0, //当前选中的商品Price
      currentStock: 0, //当前选中的商品Stock
      isChangeNum: false, // 编辑状态下，是否修改数量，防止冒泡，跳转到详情页
      quantityList: [],
      currentQuantity: -1,
      currentDefaltSpec: [0, 0], //最低价格标识，且有库存
      isChangeSelectType: false, //判断规格是否改变
      currentIndex: -1, // 当前规格选中商品的索引
      showRule: false, // 展示活动规则
      currentMcb: null, // 当前满减活动信息
      cashBackReduce: 0, // 满减活动优惠金额
      bindPhoneSetting: null,
      vipType: localStorage.getItem("vipType" + localStorage.getItem("userId")),
      ckFrom: global.ckFrom, // 类型
      showPresent: false, // 满减赠赠品半弹窗
      currentActivity: null, // 当前满减赠活动商品
      checkedNum: 0, // 购物车选择商品数量
      customPointName: localStorage.getItem("customPointName"), // 积分名称
    };
  },
  created() {
    utilJs.appShare(this);
  },
  computed: {
    // 判断是否再限时折扣中
    isInFlashSales() {
      return function(item) {
        return item.flashSales && item.flashSales.sales.status == 2 && item.optimal && item.optimal.optimalPriceType == 101;
      }
    },
    // 获取满减赠活动结束时间
    getEndTime() {
      return function(time) {
        time = time.replace(/-/g, "/")
        let date = new Date(time);
        let month = date.getMonth() + 1;
        let day = date.getDate();
        let hours = date.getHours();
        let minutes = date.getMinutes();
        return `${month > 9 ? month : '0' + month}月${day > 9 ? day : '0' + day}日 ${hours > 9 ? hours : '0' + hours}:${minutes > 9 ? minutes : '0' + minutes}结束`
      }
    },
    // 判断活动中被使用满减的阶级
    getCashBackUse() {
      return function(item) {
        let useMcbgId = this.getcashBack(item.products, item.contents, item.ruleType).useMcbgId;
        let useMcb = item.contents.filter(mItem => {return mItem.mcbgId == useMcbgId}).length > 0 ? item.contents.filter(mItem => {return mItem.mcbgId == useMcbgId})[0] : null;
        return useMcb
      }
    },
    // 获取价格样式处理
    getTotalPrice() {
     return utilJs.priceStyleChange(this.totalPrice, 'c-fs22')
    },
    // 商品数量添加的最大值限制 isSelectSpecifications这个是针对购物车选择商品的规格而传得参数
    shopNumberMax() {
      return function(item, isSelectSpecifications) {
        let stock = 0;
        if (!isSelectSpecifications) {
          stock = item.stock;
        } else {
          let currentSpecItemInfos = this.specItemInfos.filter(i => i.itemGroup == JSON.stringify(this.currentDefaltSpec))[0];
          if (currentSpecItemInfos) stock = currentSpecItemInfos.stock;
        }
        let max = item && this.isInFlashSales(item) ?
          ((item.flashSales.limit - (item.buyCount) * 1) >= 0 && item.flashSales.limit != 0 ? (item.flashSales.limit - (item.buyCount) * 1) : stock) :
          (item && item.limitType != -1 ? ((item.limitNumber - item.purchasedNum) > stock ? stock : (item.limitNumber - item.purchasedNum)) : stock)
        return max
      }
    },
    // 运算出活动文字
    getActivityTxt() {
      return function(id, type, isReach) {
        let txt1 = ''; // 已满*元/件，已减*元/打*折，包邮
        let txt2 = ''; // 再购*元/件立享[满减*元/打*折，包邮]
        let currentInfo = this.shopCartList.filter(item => {return item.mcbId == id})[0];
        if (!currentInfo) return
        let cashBack = this.getcashBack(currentInfo.products, currentInfo.contents, currentInfo.ruleType);
        let total = utilJs.toMyFixed2(currentInfo.products.reduce((mPrice, mItem) => {
          return mPrice + (mItem.price * 1) * mItem.quantity;
        }, 0));
        let currentCon = cashBack.useMcbgId != 0 ? currentInfo.contents.filter(item => {return cashBack.useMcbgId == item.mcbgId})[0] : null;
        if (type == 1) {
          txt1 = currentCon ? `已${currentCon.detail.title}${currentCon.isDiscount == 1 ? '，已' + currentCon.detail.amount : ''}${currentCon.isFreeShipping == 1 ? '，包邮' : ''}${currentCon.isSendProd == 1 ? '，' + currentCon.detail.prod : ''}${currentCon.isSendPoints == 1 ? '，' + currentCon.detail.points : ''}${currentCon.isSendDiscount == 1 ? '，' + currentCon.detail.discount : ''}` : '';
        } else {
          txt1 = currentCon ? `${currentCon.detail.title}${currentCon.isDiscount == 1 ? '，已' + currentCon.detail.amount : ''}${currentCon.isFreeShipping == 1 ? '，包邮' : ''}${currentCon.isSendProd == 1 ? '，' + currentCon.detail.prod : ''}${currentCon.isSendPoints == 1 ? '，' + currentCon.detail.points : ''}${currentCon.isSendDiscount == 1 ? '，' + currentCon.detail.discount : ''}` : '';
        }
        // 判断是否是最高级的优惠 阶梯获取最高级 循环获取单级优惠
        let isMost = type == 1 ? (cashBack && cashBack.useMcbgId > 0 ? currentInfo.contents.filter(item => {return currentCon.grade < item.grade}) : currentInfo.contents) : (type == 2 ? currentInfo.contents : []);
        if (isMost.length > 0) {
          let nextGrade = isMost[0];
          let grap = type == 1 ? utilJs.toMyFixed2(nextGrade.backType == 1 ? nextGrade.thresholdAmount - total : nextGrade.thresholdAmount - cashBack.quantity) : utilJs.toMyFixed2(nextGrade.backType == 1 ? nextGrade.thresholdAmount * (cashBack.loop + 1) - total : nextGrade.thresholdAmount * (cashBack.loop + 1) - cashBack.quantity);
          txt2 = (`再购${nextGrade.backType == 1 ? grap + '元' : grap + '件'}立享[${nextGrade.detail ? nextGrade.detail.title + nextGrade.detail.amount + nextGrade.detail.ship + nextGrade.detail.prod + nextGrade.detail.points + nextGrade.detail.discount : ''}]`)
        }
        if (isReach) {
          return currentCon == null ? '去凑单' : '再逛逛';
        } else {
          return `${txt1 + ((currentCon && type == 2) || (type == 1 && cashBack && cashBack.useMcbgId > 0 && isMost.length >= 1) ? '，' : '')}${(type == 1 && isMost.length >= 1) || (type == 2) ? txt2 : ''}`;
        }
      }
    },
    // 满减活动满减信息
    getCashBackTxt() {
      let txt = '';
      this.currentMcb.contents.forEach((item, index) => {
        if (item.isDiscount == 1) {
          txt = txt + item.detail.title + item.detail.amount + (index == (this.currentMcb.contents.length - 1) ? '' : '；');
        }
      })
      return txt;
    },
    // 显示"、送x张无门槛券、x张折扣券、送x积分"
    getCashBackPresent() {
      return function(discountInfo) {
        let sendDiscount = '';
        let sendPoints = '';
        if (discountInfo.isSendDiscount == 1) {
          sendDiscount = `${discountInfo.isSendProd == 1 ? '、' : ''}送`
          discountInfo.sendDiscountList .forEach((item, index) => {
              sendDiscount = `${sendDiscount}${item.number}张${item.redeemCodeType == 1 ? '兑换码' : (item.redeemCodeType == 2 ? '代金券' : (item.redeemCodeType == 3 ? '满减券' : (item.redeemCodeType == 4 ? '抵价券' : '折扣券')))}${index == (discountInfo.sendDiscountList.length - 1) ? '' : '、'}`
          })
        }
        if (discountInfo.isSendPoints == 1) {
          sendPoints = `${discountInfo.isSendDiscount == 1 || discountInfo.isSendProd == 1 ? '、' : ''}送${discountInfo.points}${this.customPointName}`;
        }
        return sendDiscount + sendPoints;
      }
    },
    // 满减活动包邮信息
    getFreeShipping() {
      let txt = '';
      let list = this.currentMcb.contents.filter(item => {return item.isFreeShipping == 1});
      list.forEach((item, index) => {
        txt = txt + item.detail.title + item.detail.ship + (index == (list.length - 1) ? '' : '；')
      })
      return txt;
    },
  },
  mounted() { },
  watch: {
    //监听购物车列表数据变化，自动计算总价格
    shopCartList: {
      handler(newList, oldList) {
        this.cashBackReduce = 0;
        //获取选中的所有商品
        selectArr = [];
        newList.forEach(item => {
          if (item.mcbId != null) {
            let arr = item.products.filter(mItem => {return mItem.isChecked == 1});
            let obj = {
              mcbId: item.mcbId,
              ruleType: item.ruleType,
              products: arr,
              contents: item.contents
            }
            if (arr.length > 0) selectArr.push(obj);
          } else if (item.mcbId == null && item.isChecked == 1) {
            selectArr.push(item);
          }
        })
        this.selectAll = true;
        newList.forEach((item, index) => {
          if (item.mcbId) {
            let allSelect = item.products.every(it => it.isChecked == 1 || (it.enableChainModel && !this.isEdit));
            if (allSelect == false) {
              this.selectAll = false;
            }
          } else {
            if (item.isChecked == -1 && (!item.enableChainModel || this.isEdit)) {
            this.selectAll = false;
            }
          }
        })
        //计算选中的商品的总价格
        this.totalPrice = utilJs.toMyFixed2(selectArr.reduce((price, item, index) => {
          if (item.mcbId) {
            let products = item.products.filter(mItem => {return mItem.isChecked == 1});
            let info = this.getcashBack(products, item.contents, item.ruleType);
            return price + info.price;
          } else {
            return price + (item.optimal.optimalPrice * 1) * item.quantity;
          }
        }, 0));
        this.cashBackReduce = utilJs.toMyFixed2(selectArr.reduce((price, item, index) => {
          if (item.mcbId) {
            let products = item.products.filter(mItem => {return mItem.isChecked == 1});
            let info = this.getcashBack(products, item.contents, item.ruleType);
            return price + info.reduce;
          } else {
            return price;
          }
        }, 0));
        if (newList) {
          this.checkedNum = 0;
          newList.forEach(item => {
            if (item.isChecked == 1 && !item.mcbId) this.checkedNum++
            if (item.mcbId) {
              this.checkedNum = this.checkedNum + item.products.filter(it => it.isChecked == 1).length
            }
          })
        }

      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    // 点击显示赠品
    clickShowPresent(item) {
      this.currentActivity = this.getCashBackUse(item);
      this.$nextTick(() => {
        this.showPresent = true;
      })
    },
    changeCurrentMcbId(id) {
      this.currentMcb = this.shopCartList.filter(item => {return item.mcbId == id})[0];
      this.showRule = true;
    },
    // 计算满减优惠
    getcashBack(products, contents, type) {
      let useMcbgId = 0;
      let reduce = 0;
      let actPrice = products.reduce((mPrice, mItem) => {
        return mPrice + (mItem.price * 1) * mItem.quantity;
      }, 0);
      let quantity = products.reduce((i, item) => {
        return i + item.quantity;
      }, 0)
      let loop = 0;
      // 阶级满减
      if (type == 1) {
        for (let mItem of contents) {
          if (((actPrice >= mItem.thresholdAmount) && mItem.backType == 1) || (products && (quantity >= mItem.thresholdAmount) && mItem.backType == 2)) {
            useMcbgId = mItem.mcbgId;
          }
        }
        if (useMcbgId && useMcbgId > 0) {
          let useMcb = contents.filter(mItem => {return mItem.mcbgId == useMcbgId})[0];
          if (useMcb.isDiscount == 1) {
            if (useMcb.discountType == 1) {
              if ((actPrice - useMcb.backAmount) < 0) {
                reduce = actPrice;
                actPrice = 0;
              } else {
                reduce = useMcb.backAmount;
                actPrice = actPrice - useMcb.backAmount;
              }
            } else {
              reduce = actPrice - (useMcb.backDiscount * 1 / 100) * actPrice;
              actPrice = (useMcb.backDiscount * 1 / 100) * actPrice;
            }
          } else {
            reduce = 0;
          }
        }
        return {useMcbgId: useMcbgId, price: actPrice, quantity: quantity, reduce: reduce}
      // 循环满减 (只有金额累加满减无打折满减)
      } else {
        let useMcbgId = 0;
        if (((actPrice >= contents[0].thresholdAmount) && contents[0].backType == 1) || (products && (quantity >= contents[0].thresholdAmount) && contents[0].backType == 2)) {
          useMcbgId = contents[0].mcbgId;
        }
        let useMcb1 = contents.filter(mItem => {return mItem.mcbgId == useMcbgId})[0];
        if (useMcb1 == null) {
          return {useMcbgId: useMcbgId, price: actPrice, quantity: quantity, loop: loop, reduce: reduce}
        }
        loop = useMcb1.backType == 1 ? Math.floor(actPrice / useMcb1.thresholdAmount) : Math.floor(quantity / useMcb1.thresholdAmount);
        if (useMcb1.isDiscount == 1) {
          if ((actPrice - (useMcb1.backAmount * loop)) < 0) {
            reduce = actPrice;
            actPrice = 0;
          } else {
            actPrice = actPrice - (useMcb1.backAmount * loop);
            reduce = (useMcb1.backAmount * loop);
          }
        } else {
          reduce = 0;
        }
        return {useMcbgId: useMcbgId, price: actPrice, quantity: quantity, loop: loop, reduce: reduce}
      }
    },
    // 跳转到活动页面
    gocashBackAct(id) {
      this.$routerGo(this, "push", {
        path: "/mall/cashBackActivity/cashBackActivity",
        query: { mcbId: id }
      });
    },
    //加入购物车
    joinCart(info) {
      let currentSpecItemInfos = this.specItemInfos.find(item => item.itemGroup == JSON.stringify(info.selectSpec))
      this.currentSpecItemInfos = currentSpecItemInfos;
      this.currentStock = info.stock;
      this.currentQuantity = info.selectShopNum;
      this.currentGsiiId = this.currentSpecItemInfos.gsiiId;
      this.currentPrice = this.currentSpecItemInfos.price;
      if (this.currentSpecItemInfos == null || !info) {
        this.$showCjToast({
          text: "请选择商品",
          type: "warn",
          time: 1500
        });
        return;
      }
      if (this.currentQuantity > this.currentStock) {
        this.$showCjToast({
          text: "添加数量不能大于库存",
          type: "warn",
          time: 1500
        });
        return;
      }
      if (this.flashSales && this.flashSales.sales.status == 2 && this.shopInfo.optimal && this.shopInfo.optimal.optimalPriceType == 101 && this.flashSales.limit != 0) {
        if (this.flashSales.limit < this.currentQuantity) {
          this.$showCjToast({
            text: "每人仅限购" + this.flashSales.limit + "件",
            type: "warn",
            time: 1500
          });
          return;
        }
      }
      utilJs.postMethod(
        global.apiurl + "goods/addToCart",
        {
          mgId: this.currentMgId,
          quantity: this.currentQuantity,
          gsiiId: this.currentGsiiId,
          price: this.currentPrice,
          mcId: this.currentMcId
        },
        res => {
          this.showSpecifications = false;
          this.selectAll = false;
          pageIndex = 1;
          this.getShopCartList();
        }
      );
    },
    onShowSpecifications(mgId, mcId, index, isSelect, mIndex) {
      if (index > -1 && mIndex == null) {
        this.currentIndex = index;
        this.currentQuantity = this.quantityList[index];
      } else if (index > -1 && mIndex > -1) {
        this.currentIndex = [index, mIndex];
        this.currentQuantity = this.quantityList[index].itemQua[mIndex];
      } else if (index == null && mIndex == null) {
        this.currentIndex = -1;
        this.currentQuantity = 1;
      }
      this.specItemInfos = [];
      this.currentSpecItemInfos = null;
      this.currentMgId = -1;
      this.currentGsiiId = -1;
      this.currentPrice = 0;
      this.currentStock = 0;
      this.currentMcId = mcId;
      this.getShopInfo(mgId, isSelect, mIndex);
    },
    // 关闭规格弹窗
    closeSpecModal() {
      this.showSpecifications = false;
    },
    checklearInvalidGoods() {
      this.$cjConfirm({
        title: '提醒',
        message: '确认清空失效列表？',
        onConfirm:() => {
          this.clearInvalidGoods();
        }
      })
    },
    // 清空失效列表
    clearInvalidGoods() {
      let invalidMcIds = [];
      this.cartInvalidGoods.forEach(i => invalidMcIds.push(i.mcId));
      let data = {
        invalidMcIds: invalidMcIds
      };
      utilJs.postMethod(global.apiurl + "goods/clearInvalidGoods", data,
        res => {
          this.$showCjToast({
            text: "失效列表已清空",
            type: "success",
            time: 1500
          });
          pageIndex = 1;
          this.shopCartList = [];
          this.cartInvalidGoods = [];
          this.getShopCartList();
        });
    },
    // 获取商品对应规格的最优价格
    getSpecOptimalPrice(mgId, gsiiId) {
      return new Promise((resolve, reject) => {
        utilJs.getMethod(
        `${global.apiurl}goods/getSpecOptimalPrice?mgId=${mgId}&gsiiId=${gsiiId}`,
        res => {
          resolve(res.optimal)
        })
      })
    },
    //获取商品规格
    getShopInfo(mgId, isSelect, mIndex) {
      utilJs.getMethod(
        global.apiurl + "goods/goodsDetail?mgId=" + mgId,
        async res => {
          this.flashSales = res.flashSales;
          this.currentMgId = res.goods.mgId;
          this.shopInfo = res.goods;
          this.specs = res.specs;
          this.currentDefaltSpec = isSelect && mIndex == null ? (this.shopCartList[this.currentIndex] ? this.shopCartList[this.currentIndex].itemArr : []) :
                                  (isSelect && mIndex > -1 ? this.shopCartList[this.currentIndex[0]].products[this.currentIndex[1]].itemArr : (res.goods.defaltSpec ? res.goods.defaltSpec : []));
          this.specItems = res.specItems;
          let defaultStock = res.goods.stock;
          this.specItemInfos = res.specItemInfos;
          this.showSpecifications = true;
          let defaultPrice = this.shopInfo.price;
          let optimal = this.shopInfo.optimal;
          const MAX_BUY_TYPE_MAP = {
            '1': '每天',
            '2': '每周',
            '3': '每月',
            '4': '每季度',
            '5': '每半年',
            '6': '每年',
            '7': '每次'
          };
          if (this.currentDefaltSpec) {
            let specInfo = res.specItemInfos.find(item => item.itemGroup == JSON.stringify(this.currentDefaltSpec));
            defaultStock = specInfo.stock;
            defaultPrice = specInfo.price;
            if (!specInfo.optimal) {
              specInfo.optimal = await this.getSpecOptimalPrice(mgId, specInfo.gsiiId);
              optimal = specInfo.optimal;
              res.specItemInfos.forEach(item => {
                if (item.gsiiId == specInfo.gsiiId) {
                  item.optimal = specInfo.optimal
                }
              })
            }
            falshSalesPrice = specInfo.flashPrice;
          }
          let defaultCover = this.shopInfo.avatar ? this.shopInfo.avatar : '';
          let falshSalesPrice = res.flashSales ? res.flashSales.price : 0;
          let defaultOriginalPrice = this.shopInfo.originalPrice * 1 > 0 ? this.shopInfo.originalPrice : this.shopInfo.price;
          let minBuyNum = this.shopInfo.minOrderQuantity || 1;
          let maxDefaultInputNum = this.shopInfo.limitType != -1 ? (this.shopInfo.limitNumber - this.shopInfo.purchasedNum) : defaultStock;
          let maxBuyNum = this.shopInfo.limitType != -1 ? this.shopInfo.limitNumber : 0;
          let maxBuyNumText = this.shopInfo.limitType == 1 ? '' : MAX_BUY_TYPE_MAP[this.shopInfo.limitCycleType];
          maxBuyNumText = maxBuyNum ? `(${maxBuyNumText}限购${maxBuyNum}件)` : '';
          let specs = this.specs;
          let specItems = this.specItems;
          let specItemInfos = this.specItemInfos;
          let limitInfo = {
            limitType: this.shopInfo.limitType,
            limitNumber: this.shopInfo.limitNumber,
            purchasedNum: this.shopInfo.purchasedNum
          }
          let currentSpecDeposit = this.currentSpecDeposit;
          let showPriceBar = this.vipType != 1;
          let specInfo = {
            defaultCover,
            defaultPrice,
            falshSalesPrice,
            defaultOriginalPrice,
            defaultStock,
            minBuyNum,
            maxDefaultInputNum,
            maxBuyNumText,
            specs,
            specItems,
            specItemInfos,
            selectSpec: this.currentDefaltSpec,
            limitInfo,
            currentSpecDeposit,
            showPriceBar,
            vipType: this.vipType,
            vipDiscountType: this.shopInfo.vipDiscountType || 1,
            isMarketing: res.flashSales ? true : false,
            optimal,
            fromType: 2,
            vipDiscount: res.vipDiscount,
            svipDiscount: res.svipDiscount,
            commonProdInfo: res.commonProdInfo,
            mgId: mgId
          }
          let goods = this.shopCartList.find (item => item.mgId == mgId);
          specInfo.chainInfo = goods.chainInfo;
          if (this.isChangeSelectType == false) {
            this.showSpecifications = true;
          }
          // 多规格默认选中商品规格
          this.$nextTick(() => {
            this.$refs.shopSpec.public_initSpecInfo(specInfo);
          })
        });
    },
    //获取购物车列表
    getShopCartList() {
      if (this.dataStatus == 'LOADING') {
        return;
      }
      this.dataStatus = 'LOADING';
      utilJs.getMethod(global.apiurl + "goods/cart?page=" + pageIndex, res => {
        // 后台最多传最新的一页失效列表
        if (res.cartInvalidGoods) {
          this.cartInvalidGoods = res.cartInvalidGoods.data;
        }
        if (pageIndex == 1) {
          let cartList = res.cartGoods.data;
          this.freeShipping = res.freeShipping;
          sourceCartList = JSON.parse(JSON.stringify(cartList));
          this.shopCartList = [...cartList];
          this.recommendList = res.hotGoods;
          let that = this;
          that.shopCartList.forEach((item, index) => {
            if (item.mcbId) {
              let obj = {itemQua: []};
              item.products.forEach(mItem => {
                obj.itemQua.push(mItem.quantity);
              })
              that.$set(that.quantityList, index, obj);
            } else {
              that.$set(that.quantityList, index, Number(item.quantity));
            }
          });
        } else {
          let cartList = res.cartGoods.data;
          sourceCartList = [...sourceCartList, ...cartList];
          this.shopCartList = [...this.shopCartList, ...cartList];
          let that = this;
          that.shopCartList.forEach((item, index) => {
            if (item.mcbId) {
              let obj = {itemQua: []};
              item.products.forEach(mItem => {
                obj.itemQua.push(mItem.quantity);
              })
              that.$set(that.quantityList, index, obj);
            } else {
              that.$set(that.quantityList, index, Number(item.quantity));
            }
          });
        }
        if (res.cartGoods.next_page_url == null) {
          this.dataStatus = res.cartGoods.length == 0 ? 'NO_DATA' : 'NO_MORE_DATA';
        } else {
          this.dataStatus = 'HAS_MORE_DATA';
          pageIndex++;
        }
        // 满减跳转过来选中对应商品
        if (!this.$route.query.mcbId || this.$route.query.mcbId.length == 0) return;
        let mcbId = this.$route.query.mcbId;
        this.shopCartList.forEach((item, index) => {
          if (item.mcbId == mcbId) {
            item.products.forEach((mItem, mIndex) => {
              this.$set(this.shopCartList[index].products[mIndex], 'isChecked', 1);
            })
          }
        })
      });
    },
    //点击编辑
    clickEdit() {
      if (this.isEdit) {
        this.isEdit = false;
        this.removeChainModel();
      } else {
        //进入编辑
        this.isEdit = true;
      }
    },
    changeNumber(item) {
      let cartInfos = [];
      cartInfos.push({
        mcId: item.mcId,
        quantity: item.quantity,
        isChecked: item.isChecked
      });
      utilJs.postMethod(
        global.apiurl + "goods/editCartSave",
        { cartInfos: cartInfos },
        res => {
          // 此交互先不展示提示
          // this.$showCjToast({
          //   text: "保存成功",
          //   type: "success",
          //   time: 1500
          // });
          // sourceCartList = JSON.parse(JSON.stringify(this.shopCartList));
        }
      );
    },
    isShowLimitToast(limitNumber, purchasedNum, quantity) {
      if (limitNumber <= purchasedNum) {
        this.$showCjToast({
          text: '您已购买过该商品，当前不能购买更多了',
          type: "warn",
          time: 1500
        });
      } else if (limitNumber <= (purchasedNum + quantity)) {
        this.$showCjToast({
          text: '当前不能购买更多了',
          type: "warn",
          time: 1500
        });
      }
    },
    addNum(index, mIndex) {
      let item = null;
      let quantity = 0;
      if (index > -1 && mIndex > -1) {
        item = this.shopCartList[index].products[mIndex];
        quantity = this.quantityList[index].itemQua[mIndex];
      } else if (index > -1 && mIndex == null) {
        item = this.shopCartList[index];
        quantity = this.quantityList[index];
      }
      if (quantity >= this.shopNumberMax(item)) {
        if (item && this.isInFlashSales(item) && (item.flashSales.limit - (item.buyCount) * 1) == 0 && item.flashSales.limit != 0) {
          this.isShowLimitToast(item.flashSales.limit, (item.buyCount) * 1, quantity);
          return
        } else if (item && item.limitType != -1) {
          this.isShowLimitToast(item.limitNumber, item.purchasedNum, quantity);
          return
        } else {
          return
        }
      }
      if (index > -1 && mIndex > -1) {
        this.$set(this.quantityList[index].itemQua, mIndex, Number(quantity) + 1);
        this.$set(this.shopCartList[index].products[mIndex], "quantity", Number(quantity) + 1);
        this.changeNumber(this.shopCartList[index].products[mIndex]);
      } else if (index > -1 && mIndex == null) {
        this.$set(this.quantityList, index, Number(quantity) + 1);
        this.$set( this.shopCartList[index], "quantity", Number(quantity) + 1);
        this.changeNumber(this.shopCartList[index]);
      }
    },
    subNum(index, mIndex) {
      let item = null;
      let quantity = 0;
      if (index > -1 && mIndex > -1) {
        item = this.shopCartList[index].products[mIndex];
        quantity = this.quantityList[index].itemQua[mIndex];
      } else if (index > -1 && mIndex == null) {
        item = this.shopCartList[index];
        quantity = this.quantityList[index];
      }
      if ((quantity == 1 && (item.minOrderQuantity * 1 <= 0)) ||
        (item.minOrderQuantity > 0 && (quantity <= item.minOrderQuantity))) {
        return;
      }
      if (index > -1 && mIndex > -1) {
        this.$set(this.quantityList[index].itemQua, mIndex, Number(quantity) - 1);
        this.$set(this.shopCartList[index].products[mIndex], "quantity", Number(quantity) - 1);
        this.changeNumber(this.shopCartList[index].products[mIndex]);
      } else if (index > -1 && mIndex == null) {
        this.$set(this.quantityList, index, quantity - 1);
        this.$set( this.shopCartList[index], "quantity", quantity - 1);
        this.changeNumber(this.shopCartList[index]);
      }
    },
    changeInputNum(index, mIndex) {
      let quantity = event.target.value.replace(/[^0-9]/g, '');
      const item = index > -1 && mIndex > -1 ? this.shopCartList[index].products[mIndex] : this.shopCartList[index];
      const maxNum = this.shopNumberMax(item);
      // 限购
      if (quantity >= maxNum) {
        if (
          (item.optimal && item.optimal.optimalPriceType == 101 && item.flashSales.sales.status == 2 && (item.flashSales.limit - (item.buyCount) * 1) == 0 && item.flashSales.limit != 0) ||
          (item.limitType != -1)
        ) {
          if (index > -1 && mIndex > -1) {
            this.$set(this.quantityList[index].itemQua, mIndex, maxNum);
            this.$set(this.shopCartList[index].products[mIndex], "quantity", maxNum);
          } else if (index > -1 && !mIndex) {
            this.$set(this.quantityList, index, maxNum);
            this.$set(this.shopCartList[index], "quantity", maxNum);
          }
          return
        }
      } else if ( // 起售
        (quantity == 1 && (item.minOrderQuantity * 1 <= 0)) ||
        (item.minOrderQuantity > 0 && (quantity <= item.minOrderQuantity))
      ) {
        if (index > -1 && mIndex > -1) {
          this.$set(this.quantityList[index].itemQua, mIndex, item.minOrderQuantity);
          this.$set(this.shopCartList[index].products[mIndex], "quantity", item.minOrderQuantity);
        } else if (index > -1 && !mIndex) {
          this.$set(this.quantityList, index, item.minOrderQuantity);
          this.$set(this.shopCartList[index], "quantity", item.minOrderQuantity);
        }
        return;
      }
      if (index > -1 && mIndex > -1) {
        this.$set(this.quantityList[index].itemQua, mIndex, quantity);
        this.$set(this.shopCartList[index].products[mIndex], "quantity", quantity);
      } else if (index > -1 && !mIndex) {
        this.quantityList[index] = quantity;
        this.$set(this.shopCartList[index], "quantity", quantity);
      }
    },
    inputFocus(index, mIndex) {
      let quantity = 0;
      if (index > -1 && mIndex > -1) {
        quantity = this.quantityList[index].itemQua[mIndex];
      } else if (index > -1 && mIndex == null) {
        quantity = this.quantityList[index];
      } else if (index == '') {
        quantity = 1
      }
      let tmpNum = JSON.stringify(quantity);
      this.currentQuantity = Number(JSON.parse(tmpNum))
    },
    finishInput(index, mIndex) {
      let item = null;
      let quantity = 0;
      if (index > -1 && mIndex > -1) {
        item = this.shopCartList[index].products[mIndex];
        quantity = this.quantityList[index].itemQua[mIndex];
      } else if (index > -1 && mIndex == null) {
        item = this.shopCartList[index];
        quantity = this.quantityList[index];
      } else if (index == '') {
        quantity = 1
      }
      const maxNum = this.shopNumberMax(item);
      // 限购
      if (quantity >= maxNum) {
        if (
          (item.optimal && item.optimal.optimalPriceType == 101 && item.flashSales.sales.status == 2 && (item.flashSales.limit - (item.buyCount) * 1) == 0 && item.flashSales.limit != 0) ||
          (item.limitType != -1)
        ) {
          if (index > -1 && mIndex > -1) {
            this.$set(this.quantityList[index].itemQua, mIndex, maxNum);
            this.$set(this.shopCartList[index].products[mIndex], "quantity", maxNum);
          } else if (index > -1 && !mIndex) {
            this.$set(this.quantityList, index, maxNum);
            this.$set(this.shopCartList[index], "quantity", maxNum);
          }
          return
        }
      } else if ( // 起售
        (quantity == 1 && (item.minOrderQuantity * 1 <= 0)) ||
        (item.minOrderQuantity > 0 && (quantity <= item.minOrderQuantity))
      ) {
        if (index > -1 && mIndex > -1) {
          this.$set(this.quantityList[index].itemQua, mIndex, item.minOrderQuantity);
          this.$set(this.shopCartList[index].products[mIndex], "quantity", item.minOrderQuantity);
        } else if (index > -1 && !mIndex) {
          this.$set(this.quantityList, index, item.minOrderQuantity);
          this.$set(this.shopCartList[index], "quantity", item.minOrderQuantity);
        }
        return;
      }
      if (quantity < 1) {
        if (index > -1 && mIndex > -1) {
          this.$set(this.quantityList[index].itemQua, mIndex, Number(this.currentQuantity));
        } else if (index > -1 && mIndex == null) {
          this.$set(this.quantityList, index, Number(this.currentQuantity));
        }
        this.$showCjToast({
          text: "输入数值应大于0",
          type: "success",
          time: 1500
        });
        return;
      }
      if (quantity > ((this.isInFlashSales(item) && item.flashSales.limit != 0) ? item.flashSales.limit - item.buyCount : item.stock)) {
        this.$showCjToast({
          text: "库存不足，请重新输入！",
          type: "success",
          time: 1500
        });
        this.isChangeNum = false;
        if (index > -1 && mIndex > -1) {
          this.$set(this.quantityList[index].itemQua, mIndex, Number(this.currentQuantity));
        } else if (index > -1 && mIndex == null) {
          this.$set(this.quantityList, index, Number(this.currentQuantity));
        }
        this.isChangeNum = true;
        return;
      }
      if (index > -1 && mIndex > -1) {
        this.$set(this.shopCartList[index].products[mIndex], "quantity", Number(this.quantityList[index].itemQua[mIndex]));
        this.changeNumber(this.shopCartList[index].products[mIndex]);
      } else if (index > -1 && mIndex == null) {
        this.$set(this.shopCartList[index], "quantity", Number(this.quantityList[index]));
        this.changeNumber(this.shopCartList[index]);
      }
    },
    //点击删除购物车商品
    delShopCart() {
      this.delShopIds = [];
      this.shopCartList.forEach(i => {
        if (i.mcbId) {
          i.products.forEach(item => {
            if (item.isChecked == 1) {
              this.delShopIds.push(item.mcId);
            }
          })
        } else {
          if (i.isChecked == 1) {
            this.delShopIds.push(i.mcId);
          }
        }
      });
      if (this.delShopIds.length == 0) {
        this.$showCjToast({
          text: "请先选择商品！",
          type: "warn",
          time: 1500
        });
        return;
      }
      this.$cjConfirm({
        message: '确认将这' + this.delShopIds.length + '件宝贝删除？',
        onConfirm:() => {
          this.onConfirmDel();
        },
        onCancel:() => {
        }
      })
    },
    //删除确认
    onConfirmDel(e) {
      let data = {
        mcIdArr: this.delShopIds
      }
      utilJs.postMethod(
        global.apiurl + "goods/deleteCartGoods", data,
        res => {
          this.$showCjToast({
            text: "删除成功",
            type: "success",
            time: 1500
          });
          let $this = this;
          this.$nextTick(() => {
            pageIndex = 1;
            // $this.shopCartList = [];
            $this.cartInvalidGoods = [];
            $this.getShopCartList();
          });
        }
      );
    },
    //点击结算
    clickSettlement() {
      if (this.bindPhoneSetting && this.bindPhoneSetting.buyBind) {
        if (utilJs.goBindMobile()) return;
      }
      let shopInfoList = [];
      let isMarketing = 0;
      let isNoMarketing = 0;
      let shopAllList = [];
      for (let item of this.shopCartList) {
        if (item.mcbId) {
          for (let mItem of item.products) {
            if (mItem.isChecked == 1) {
              if (mItem.quantity > mItem.stock) {
                this.$showCjToast({
                  text: mItem.name + "库存不足",
                  type: "warn",
                  time: 1500
                });
                return;
              }
              let info = {
                subProdId:item.socialRoomId,
                subSonProdId: item.detailId,
                mgId: mItem.mgId,
                mcId: mItem.mcId,
                avatar: mItem.avatar,
                minOrderQuantity: mItem.minOrderQuantity,
                isMail: mItem.isMail,
                name: mItem.name,
                price: mItem.price,
                originalPrice: mItem.originalPrice,
                quantity: mItem.quantity,
                shopSpecInfo: mItem.subSpec ? mItem.subSpec.split("|").join(" ") : "",
                gsiiId: mItem.gsiiId,
                postage: mItem.postage,
                stock: mItem.stock,
                freeShipping: this.freeShipping,
                isMallExpressDeliver: mItem.isMallExpressDeliver,
                isMallOfflineDeliver: mItem.isMallOfflineDeliver,
                modGroup: mItem.modGroup,
                limitType: mItem.limitType,
                limitNumber: mItem.limitNumber,
                purchasedNum: mItem.purchasedNum,
                mcbId: item.mcbId,
                vipDiscount: mItem.vipDiscount,
                svipDiscount: mItem.svipDiscount,
                commonProdInfo: mItem.commonProdInfo,
                vipDiscountType: mItem.vipDiscountType || 1,
                pointsDeduct: mItem.pointsDeduct,
                isLimitAssignUser: mItem.isLimitAssignUser,
                givenPoints: mItem.givenPoints && mItem.givenPoints > 0 ? mItem.givenPoints : 0,
              };
              if (mItem.valuationMethod && mItem.valuationMethod == 2) {
                info.valuationMethod = mItem.valuationMethod;
              }
              let discountPrice = mItem.price, chainPrice = mItem.price;
              // 身份折扣
              if (this.vipType != 1) {
                if (mItem.vipDiscountType == 1) {
                  discountPrice =
                    this.vipType == 2 ?
                    Number(mItem.price * mItem.vipDiscount / 100).toFixed(2) :
                    this.vipType == 4 ?
                    Number(mItem.price * mItem.svipDiscount / 100).toFixed(2) :
                    Number(mItem.price * mItem.commonProdInfo.agentDiscount / 100).toFixed(2);
                } else {
                  discountPrice = this.vipType == 2 ? Number(mItem.vipDiscount).toFixed(2) : this.vipType == 4 ? Number(mItem.svipDiscount).toFixed(2) : Number(mItem.commonProdInfo.agentDiscount).toFixed(2);
                }
              }
              // 链动折扣
              if ((mItem.chainProdInfo && mItem.chainProdInfo.enableOrderDiscount == 1 && mItem.chainProdInfo.orderBonus > 0 && mItem.chainProdInfo.orderBonus < mItem.price)
                || (mItem.chainProdInfo && mItem.chainProdInfo.isReorder && mItem.chainProdInfo.enableReorderDiscount == 1 && mItem.chainProdInfo.reorderBonus > 0 && mItem.chainProdInfo.reorderBonus < mItem.price)) {
                  chainPrice = mItem.chainProdInfo.isReorder && mItem.chainProdInfo.reorderBonus > 0 ? mItem.chainProdInfo.reorderBonus : mItem.chainProdInfo.orderBonus;
                  if (chainPrice <= discountPrice) {
                    info.isFromChain = true;
                    info.isReorder = mItem.chainProdInfo.isReorder && mItem.chainProdInfo.reorderBonus > 0 ? true : false;
                    info.orderBonus = mItem.chainProdInfo.isReorder && mItem.chainProdInfo.reorderBonus > 0 ? mItem.chainProdInfo.reorderBonus : mItem.chainProdInfo.orderBonus;
                  }
              }
              shopAllList.push(info);
              if (shopInfoList.filter(it => {return it.mcbId == item.mcbId}).length == 0) {
                let obj = {
                  mcbId: item.mcbId,
                  title: item.title,
                  contents: item.contents,
                  ruleType: item.ruleType,
                  products: [info]
                }
                shopInfoList.push(obj);
              } else {
                let i = 0;
                shopInfoList.forEach((it, itIndex) => {
                  if (it.mcbId == item.mcbId) {
                    i = itIndex;
                  }
                })
                shopInfoList[i].products.push(info);
              }
            }
          }
        } else {
          if (item.isChecked == 1) {
            // 处于限时折扣且价格最优
            if (item.isMarketing == 1 && item.optimal && item.optimal.optimalPriceType == 101) {
              isMarketing = 1;
            } else {
              isNoMarketing = 1;
            }
            if (item.quantity > item.stock) {
              this.$showCjToast({
                text: item.name + "库存不足",
                type: "warn",
                time: 1500
              });
              return;
            }
            if (this.isInFlashSales(item) && item.flashSales.limit != 0) {
              if (item.quantity > item.flashSales.limit - item.buyCount) {
                this.$showCjToast({
                  text: item.name + "每人仅限购" + item.flashSales.limit + "件",
                  type: "warn",
                  time: 1500
                });
                return;
              }
            }
            let info = {
              subProdId:item.socialRoomId,
              subSonProdId: item.detailId,
              mgId: item.mgId,
              mcId: item.mcId,
              avatar: item.avatar,
              minOrderQuantity: item.minOrderQuantity,
              pointsDeduct: item.pointsDeduct,
              isMail: item.isMail,
              name: item.name,
              price: item.price,
              originalPrice: item.originalPrice,
              quantity: item.quantity,
              shopSpecInfo: item.subSpec ? item.subSpec.split("|").join(" ") : "",
              gsiiId: item.gsiiId,
              postage: item.postage,
              stock: item.stock,
              freeShipping: this.freeShipping,
              vipDiscount: item.vipDiscount,
              svipDiscount: item.svipDiscount,
              commonProdInfo: item.commonProdInfo,
              vipDiscountType: item.vipDiscountType || 1,
              isMallExpressDeliver: item.isMallExpressDeliver,
              isMallOfflineDeliver: item.isMallOfflineDeliver,
              givenPoints: item.givenPoints && item.givenPoints > 0 ? item.givenPoints : 0,
              modGroup: item.modGroup,
              limitType: item.limitType,
              limitNumber: item.limitNumber,
              purchasedNum: item.purchasedNum,
              isLimitAssignUser: item.isLimitAssignUser,
              relData: item.relData,
            };
            if (item.valuationMethod && item.valuationMethod == 2 && item.freightMode == 1) {
              info.valuationMethod = item.valuationMethod;
            }
            let discountPrice = item.price, chainPrice = item.price;
            // 限时折扣
            if (this.isInFlashSales(item)) {
              info.pointsDeduct = 0; //限时购不能使用积分
              info.price = item.flashSales.price;
              info.vipDiscount = item.vipDiscountType == 1 ? 100 : item.price;
              info.svipDiscount = item.vipDiscountType == 1 ? 100 : item.price;
              info.commonProdInfo = null;
              info.noLimit = item.flashSales.limit == 0;
              info.pId = item.flashSales.pId;
              info.isFlashSales = true;
              info.stock = item.flashSales.limit != 0 ? item.flashSales.limit - item.buyCount : item.stock;
              info.salesStock = item.flashSales.limit;
              info.salesLimt = item.flashSales.limit != 0 && ((item.flashSales.limit - item.buyCount) * 1 > 0) ? (item.flashSales.limit - item.buyCount) * 1 : 0;
            }
            // 身份折扣
            if (this.vipType != 1) {
              if (item.vipDiscountType == 1) {
                discountPrice =
                  this.vipType == 2 ?
                  Number(item.price * item.vipDiscount / 100).toFixed(2) :
                  this.vipType == 4 ?
                  Number(item.price * item.svipDiscount / 100).toFixed(2) :
                  Number(item.price * item.commonProdInfo.agentDiscount / 100).toFixed(2);
              } else {
                discountPrice = this.vipType == 2 ? Number(item.vipDiscount).toFixed(2) : this.vipType == 4 ? Number(item.svipDiscount).toFixed(2) : Number(item.commonProdInfo.agentDiscount).toFixed(2);
              }
            }
            // 链动折扣
            if (
                !info.isFlashSales &&
                (item.chainProdInfo && item.chainProdInfo.enableOrderDiscount == 1 && item.chainProdInfo.orderBonus > 0 && item.chainProdInfo.orderBonus < item.price) ||
                (item.chainProdInfo && item.chainProdInfo.isReorder && item.chainProdInfo.enableReorderDiscount == 1 && item.chainProdInfo.reorderBonus > 0 && item.chainProdInfo.reorderBonus < item.price)
              ) {
                chainPrice = item.chainProdInfo.isReorder && item.chainProdInfo.reorderBonus > 0 ? item.chainProdInfo.reorderBonus : item.chainProdInfo.orderBonus;
                if (chainPrice <= discountPrice) {
                  info.isFromChain = true;
                  info.isReorder = item.chainProdInfo.isReorder && item.chainProdInfo.reorderBonus > 0 ? true : false;
                  info.orderBonus = item.chainProdInfo.isReorder && item.chainProdInfo.reorderBonus > 0 ? item.chainProdInfo.reorderBonus : item.chainProdInfo.orderBonus;
                }
            }
            shopAllList.push(info);
            shopInfoList.push(info);
          }
        }
      }
      // 判断用户不具备限购权限
      let userLimitPurchase = []; // 用户限购列表
      for (let item of shopAllList) {
        if (item.isAssignUser == 1) {
          userLimitPurchase.push(item);
        }
      }
      if (userLimitPurchase.length > 0) {
        let txt = '';
        let i = 1;
        for (let item of userLimitPurchase) {
          if (i > 2) {
            break
          }
          txt = txt + '【' + item.name + '】';
          i++;
        }
        txt = txt.length > 6 ? txt.substring(0, 6) + '...' : txt;
        this.$showCjToast({
          text: "以下商品仅限特定用户购买" + txt,
          type: "warn",
          time: 1500
        });
        return;
      }
      // 判断是否是多个满减活动一起结算
      if (shopInfoList.filter(item => {return item.mcbId != null}).length > 1) {
        this.$showCjToast({
          text: "只支持单一满减活动商品购买或搭配普通商品购买!",
          type: "warn",
          time: 1500
        });
        return;
      }
      // 判断配送方式是否相同/自提点是否有相交的区域
      let isAllExpress = shopAllList.every(item => item.isMallExpressDeliver === 1);
      let isAllOffline = shopAllList.every(item => item.isMallOfflineDeliver === 1);
      if (isAllOffline && shopAllList.length > 0) {
        let minMod = [];
        shopAllList.forEach(i => {
          minMod = i.modGroup;
          if (i.modGroup.length < minMod.length) {
            minMod = i.modGroup;
          }
        })
        let modArr = [];
        minMod.forEach(i => {
          let state = [];
          shopAllList.forEach(j => {
            if (j.modGroup.includes(i)) {
              state.push(true)
            } else state.push(false);
            const stutas = state.every(i => { return i === true })
            stutas && !modArr.includes(i) && modArr.push(i)
          })
        })
        if (modArr.length == 0) {
          this.$showCjToast({
            text: "不同配送方式的商品暂不支持同时结算，请分开下单!",
            type: "warn",
            time: 1500
          });
          return;
        };
      }
      if (isAllExpress == false && isAllOffline == false && shopAllList.length > 0) {
        this.$showCjToast({
          text: "不同配送方式的商品暂不支持同时结算，请分开下单!",
          type: "warn",
          time: 1500
        });
        return;
      }
      if (isMarketing == 1 && isNoMarketing == 1) {
        this.$showCjToast({
          text: "营销商品不可和普通商品一起支付!",
          type: "warn",
          time: 1500
        });
        return;
      }
      if (isMarketing == 1 && (shopInfoList.filter(item => {return item.mcbId != null}) && shopInfoList.filter(item => {return item.mcbId != null}).length > 0)) {
        this.$showCjToast({
          text: "参与营销活动商品不支持购物车一起支付!",
          type: "warn",
          time: 1500
        });
        return;
      }
      if (shopInfoList.length > 0) {
        sessionStorage.setItem("shopBuyInfo", JSON.stringify(shopInfoList));
        this.$routerGo(this, "push", {
          path: "/mall/shopSettlement/shopSettlement?shopNo="
        });
      } else {
        this.$showCjToast({
          text: "请选择商品",
          type: "warn",
          time: 1500
        });
      }
    },

    clickShop(shopNo) {
      if (this.isChangeNum) {
        this.isChangeNum = false;
        return;
      }
      //点击商品
      this.$routerGo(this, "push", {
        path: "/mall/shopDetail/shopDetail",
        query: { shopNo: shopNo || this.currentMgId }
      });
    },

    clickVisit(e) {
      //点击逛一逛
      this.$routerGo(this, "push", { path: "/mall/classification/classificationAll" });
    },
    //选择单个
    clickItemSelect(index, isChecked, mIndex, id) {
      if (isChecked) {
        if (index > -1 && mIndex == null) {
          //链动2+1的商品不允许加入购物车
          if (this.shopCartList[index].enableChainModel && !this.isEdit) {
            this.$showCjToast({
              text: '该链动商品不支持在购物车中购买',
              type: "warn",
              time: 1500
            });
            return;
          }
          this.$set(this.shopCartList[index], "isChecked", 1);
        } else if (index > -1 && mIndex > -1) {
          if (this.shopCartList[index].products[mIndex].enableChainModel && !this.isEdit) {
            this.$showCjToast({
              text: '该链动商品不支持在购物车中购买',
              type: "warn",
              time: 1500
            });
            return;
          }
          this.$set(this.shopCartList[index].products[mIndex], "isChecked", 1);
        }
        if (id != null) {
          let obj = this.shopCartList.filter(item => {return item.mcbId == id})[0];
          obj.products.forEach((item, mIndex) => {
            if (this.shopCartList[index].products[mIndex].enableChainModel && !this.isEdit) {
              this.$showCjToast({
                text: '部分链动商品不支持在购物车中购买',
                type: "warn",
                time: 1500
              });
            } else {
              this.$set(this.shopCartList[index].products[mIndex], "isChecked", 1);
            }
          })
        }
      } else {
        this.selectAll = false;
        if (index > -1 && mIndex == null) {
          this.$set(this.shopCartList[index], "isChecked", -1);
        } else if (index > -1 && mIndex > -1) {
          this.$set(this.shopCartList[index].products[mIndex], "isChecked", -1);
        }
        if (id != null) {
          let obj = this.shopCartList.filter(item => {return item.mcbId == id})[0];
          obj.products.forEach((item, mIndex) => {
            this.$set(this.shopCartList[index].products[mIndex], "isChecked", -1);
          })
        }
      }
      const item = index > -1 && mIndex == null ? this.shopCartList[index] : this.shopCartList[index].products[mIndex];
      this.changeNumber(item);
    },
    //取消选中链动2+1的商品
    removeChainModel() {
      let curCarList = [...this.shopCartList];
      for (let key of curCarList) {
        if (key.mcbId) {
          key.products.forEach(mItem => {
            if (mItem.enableChainModel)
              mItem.isChecked = -1;
          })
        } else {
          if (key.enableChainModel)
            key.isChecked = -1;
        }
      }
    },
    //点击全选
    clickSelectAll() {
      this.selectAll = !this.selectAll;
      let curCarList = [...this.shopCartList];
      if (this.selectAll) {
        for (let key of curCarList) {
          if (key.mcbId) {
            key.products.forEach(mItem => {
              if (!mItem.enableChainModel || this.isEdit)
                mItem.isChecked = 1;
            })
          } else {
            if (!key.enableChainModel || this.isEdit)
              key.isChecked = 1;
          }
        }
      } else {
        for (let key of curCarList) {
          if (key.mcbId) {
            key.products.forEach(mItem => {
              mItem.isChecked = -1;
            })
          } else {
            key.isChecked = -1;
          }
        }
      }
      this.shopCartList = [...curCarList];
    },
    //分享
    wechatShare: function () {
      let title = window.localStorage.getItem("shareTitle");
      let shareImg = window.localStorage.getItem("shareLogo");
      let shareUrl =
        window.location.href.split("#")[0] +
        "#/?refereeId=" +
        localStorage.getItem("userId");
      let shareDesc = window.localStorage.getItem("shareDesc");
      utilJs.wechatConfig(shareUrl, title, shareImg, shareDesc, function () { });
    },
    //手机端分享
    appShare: function () {
      var shareUrl =
        window.location.href.split("#")[0] +
        "#/?refereeId=" +
        localStorage.getItem("userId");
      utilJs.appShareTrue("", "", shareUrl, "");
    },
    windowScrollFunction: function () {
      utilJs.handleLoading(() => {
        if (this.dataStatus == 'HAS_MORE_DATA' && this.shopCartList.length > 0) {
          this.getShopCartList();
        }
      });
    }
  },
  activated() {
    setDocumentTitle("购物车");// eslint-disable-line
    this.isEdit = false; //是否编辑状态
    this.totalPrice = 0.0;
    this.selectAll = false; //是否全选
    this.dataStatus = "HAS_MORE_DATA";
    this.showSpecifications = false;
    this.delShopIds = [];
    this.specItems = [];
    this.specItemInfos = [];
    this.currentSpecItemInfos = null;
    this.flashSales = null;
    this.currentMcId = -1;
    this.currentMgId = -1;
    this.currentGsiiId = -1;
    this.currentPrice = 0;
    this.currentStock = 0;
    this.quantityList = [];
    this.currentQuantity = -1;
    this.currentIndex = -1;
    this.cashBackReduce = 0;
    this.showPresent = false;
    this.currentActivity = null; // 当前满减赠活动商品
    this.checkedNum = 0; // 购物车选择数量
    pageIndex = 1;
    sourceCartList = [];
    selectArr = [];
    this.showRule = false;
    this.currentMcb = 0;
    getBindPhoneSetting(global.ckFrom.shopping).then(res => {
      this.bindPhoneSetting = res;
    });
    this.getShopCartList();
    this.wechatShare();
    window.addEventListener('scroll', this.windowScrollFunction);
  },
  deactivated() {
    window.removeEventListener('scroll', this.windowScrollFunction);
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->

<style scoped>
.cart-name-box {
  /* min-height: 4.5rem; */
}
.shop-cart-empty-img {
  width: 8.45rem;
  height: 8.45rem;
  margin-top: 0.75rem;
}
.btn-cart-visit {
  width: 5.25rem;
  height: 1.65rem;
  line-height: 1.65rem;
  color: #777777;
  border-radius: 0.5rem;
  border: 1px solid #777777;
  text-align: center;
}
.shop-cart-bottom {
  position: fixed;
  bottom: 0;
  height: 2rem;
  width: 100%;
  display: -webkit-flex;
  display: flex;
  align-items: center;
  -webkit-align-items: center;
  background-color: #fff;
  max-width: 640px;
  z-index: 11;
}
.btn-cart-clear {
  width: 5rem;
  min-width: 5rem;
  height: 2rem;
  line-height: 2rem;
  text-align: center;
  color: #fff;
  font-size: 0.7rem;
  background-color: #ff6400;
}
.masker-specifications-content {
  background-color: #fff;
  max-height: 16rem;
  height: 16rem;
  width: 100%;
}
.masker-content-img {
  width: 3.75rem;
  max-height: 3.75rem;
}
.active-attr {
  background-color: #fffcfa;
}
.operation-button {
  display: inline-block;
  width: 1.1rem;
  height: 0.8rem;
  line-height: 0.8rem;
  cursor: pointer;
  text-align: center;
  font-size: 0.6rem;
}
.sub-button {
  border-top-left-radius: 0.1rem;
  border-bottom-left-radius: 0.1rem;
}
.add-button {
  border-top-right-radius: 0.1rem;
  border-bottom-right-radius: 0.1rem;
}

.disabled-click {
  color: #ccc;
}
input:focus {
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.bgF4F5F7 {
  background-color: #f4f5f7;
}
input {
  width: 1.7rem;
  height: 0.8rem;
  text-align: center;
  font-size: 0.5rem;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  border-radius: 0.2rem;
  border: 1px solid #f2f2f2;
}
.c-mt15 {margin-top: 0.375rem;}
.c-fc-e5 {color: #e5e5e5;}
.sxIcon {
  height: 0.8rem;
  width: 0.8rem;
  display: block;
  border-radius: 50%;
  border: 1px solid #e5e5e5;
  background: #f2f2f2;
  box-sizing: border-box;
}
.c-fc-lorange {color: #FF300C;}
.tagBg {
  background-color: rgba(255,48,12,0.1);
  width: 1.2rem;
  text-align: center;
}
.tagBg1 {
  background-color: rgba(255,48,12,0.1);
  border: 1px solid rgba(255,48,12, 1);
}
.c-maxw264 {max-width: 6.6rem;}
.masker-content {
  background-color: #fff;
  width: 100%;
}
.c-maxw320 {
  width: 8rem;
}
.scale8 {
  display: inline-block;
  transform: scale(0.8);
}
.c-pl76 {
  padding-left: 1.9rem;
}
.c-pr2 {
  padding-right: 0.05rem;
}
</style>
